import { Sprite } from "@/sprites/Sprite.js";
import { AnimatedContainer } from "@/containers/AnimatedContainer.js";
export class Sprite_Base extends Sprite {
    constructor() {
        super();
        /**
         * @type {AnimatedContainer[]}
         */
        this._animationSprites = [];
        this._effectTarget = this;
        this._hiding = false;
    }

    update() {
        super.update();
        this.updateAnimationSprites();
    }

    hide() {
        this.visible=false;
    }

    show() {
        this.visible=true;
    }

    updateAnimationSprites() {
        if (this._animationSprites.length > 0) {
            let len=this._animationSprites.length;
            let sprites=null;
            for (let i = 0; i < len; i++) {
                let sprite = this._animationSprites[i];
                if (!sprite.isPlaying()) {
                    sprite.remove();
                    if(!sprites){
                        sprites=this._animationSprites.slice(0,i);
                    }
                }else if(sprites){
                    sprites.push(sprite);
                }
            }
            if(sprites){
                this._animationSprites=sprites;
            }
        }
    }

    startAnimation(animation, mirror, delay) {
        let sprite = new AnimatedContainer();
        sprite.setup(this._effectTarget, animation, mirror, delay);
        this.parent.addChild(sprite);
        this._animationSprites.push(sprite);
    }

    isAnimationPlaying() {
        return this._animationSprites.length > 0;
    }
}